home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C# & Game Programming - A…er's Guide (2nd Edition)
/
Buono 2nd Ed.iso
/
GameClasses
/
Shapes.cs
< prev
next >
Wrap
Text File
|
2004-09-07
|
16KB
|
296 lines
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace GameClasses {
public class Shapes : PlayerImageArray {
public Shapes(int n) : base(0) {}
public Shapes(int posX, int posY) : base(0) {
imagePosX = posX;
imagePosY = posY;
isActive = false;
animationStep = DEFAULTSTEP;
}
// game specific - draws an ellipse as connected to a FillPie ship
public int Exhuast(Graphics g, Brush bExhaustColor) {
switch(this.direction) {
case 1:
g.FillEllipse(bExhaustColor, this.imagePosX+21,
this.imagePosY-1, 5, 5);
break;
case 2:
g.FillEllipse(bExhaustColor, this.imagePosX+10,
this.imagePosY-4, 5, 5);
break;
case 3:
g.FillEllipse(bExhaustColor, this.imagePosX,
this.imagePosY, 5, 5);
break;
case 8:
g.FillEllipse(bExhaustColor, this.imagePosX+25,
this.imagePosY+10, 5, 5);
break;
case 4:
g.FillEllipse(bExhaustColor, this.imagePosX-5,
this.imagePosY+10, 5, 5);
break;
case 7:
g.FillEllipse(bExhaustColor, this.imagePosX+20,
this.imagePosY+22, 5, 5);
break;
case 6:
g.FillEllipse(bExhaustColor, this.imagePosX+10,
this.imagePosY+25, 5, 5);
break;
case 5:
g.FillEllipse(bExhaustColor, this.imagePosX,
this.imagePosY+22, 5, 5);
break;
}
return 0;
}
// defines the starting angle of a Pie for any given vector
public int startAngle() {
switch(this.direction) {
case 1: return(290); // southwest
case 2: return(250); // south
case 3: return(200); // southeast
case 4: return(155); // east
case 5: return(105); // northeast
case 6: return(65); // north
case 7: return(25); // northwest
case 8: return(-25); // west
}
return(0); // default northwest
}
// complex shape - reusable as a single item
public void Asteroid(Graphics g, Brush bAsteroidColor) {
Point[] PolyRoid = {
new Point(this.imagePosX-this.imageWidth/5, this.imagePosY-2*this.imageHeight/5),
new Point(this.imagePosX+this.imageWidth/5, this.imagePosY-2*this.imageHeight/5),
new Point(this.imagePosX+this.imageWidth/5, this.imagePosY-this.imageHeight/5),
new Point(this.imagePosX+2*this.imageWidth/5, this.imagePosY-this.imageHeight/5),
new Point(this.imagePosX+2*this.imageWidth/5, this.imagePosY+this.imageHeight/5),
new Point(this.imagePosX+this.imageWidth/5, this.imagePosY+this.imageHeight/5),
new Point(this.imagePosX+this.imageWidth/5, this.imagePosY+2*this.imageHeight/5),
new Point(this.imagePosX-this.imageWidth/5, this.imagePosY+2*this.imageHeight/5),
new Point(this.imagePosX-this.imageWidth/5, this.imagePosY+this.imageHeight/5),
new Point(this.imagePosX-2*this.imageWidth/5, this.imagePosY+this.imageHeight/5),
new Point(this.imagePosX-2*this.imageWidth/5, this.imagePosY-this.imageHeight/5),
new Point(this.imagePosX-this.imageWidth/5, this.imagePosY-this.imageHeight/5),};
g.FillPolygon(bAsteroidColor, PolyRoid);
}
// complex shape - reusable as a single item
public void Alien0(Graphics g, Brush bAlienColor) {
Point[] Alien = {
new Point(this.imagePosX-10, this.imagePosY-10),
new Point(this.imagePosX-5, this.imagePosY-10),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-10)};
g.FillPolygon(bAlienColor, Alien);
}
// complex shape - reusable as a single item
public void Alien1(Graphics g, Brush bAlienColor) {
Point[] Alien = {
new Point(this.imagePosX-10, this.imagePosY-10),
new Point(this.imagePosX-5, this.imagePosY-10),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+10),
new Point(this.imagePosX+5, this.imagePosY+10),
new Point(this.imagePosX+5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-10)};
g.FillPolygon(bAlienColor, Alien);
}
// complex shape - reusable as a single item
public void Alien2(Graphics g, Brush bAlienColor) {
Point[] Alien = {
new Point(this.imagePosX-5, this.imagePosY-10),
new Point(this.imagePosX+5, this.imagePosY-10),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+10, this.imagePosY-5),
new Point(this.imagePosX+10, this.imagePosY+10),
new Point(this.imagePosX+5, this.imagePosY+10),
new Point(this.imagePosX+5, this.imagePosY),
new Point(this.imagePosX-5, this.imagePosY),
new Point(this.imagePosX-5, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY-5),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX-5, this.imagePosY-10)};
g.FillPolygon(bAlienColor, Alien);
}
// complex shape - reusable as a single item
public void Alien3(Graphics g, Brush bAlienColor) {
Point[] Alien = {
new Point(this.imagePosX-10, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+10),
new Point(this.imagePosX+5, this.imagePosY+10),
new Point(this.imagePosX+5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-10)};
g.FillPolygon(bAlienColor, Alien);
}
// complex shape - reusable as a single item
public void Tank(Graphics g, Brush bTankColor, Brush bCannonColor) {
Point[] tank = {
new Point(this.imagePosX-10, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY-5),
new Point(this.imagePosX+5, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+5),
new Point(this.imagePosX+10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+10),
new Point(this.imagePosX-10, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY+5),
new Point(this.imagePosX-5, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-5),
new Point(this.imagePosX-10, this.imagePosY-10)};
g.FillPolygon(bTankColor, tank);
g.FillPie(bCannonColor, this.imagePosX-12,
this.imagePosY-12, this.imageWidth, this.imageHeight,
this.imagePosX, this.imageHeight);
}
// combination shape - reusable as a single item
public void Window(Graphics g, Brush bWindowColor) {
Brush GrayBrush = new SolidBrush(Color.Gray);
g.FillRectangle(GrayBrush, this.imagePosX,
this.imagePosY, 24, 24); // frame
g.FillRectangle(bWindowColor, this.imagePosX+2,
this.imagePosY+2, 20, 20); // glass
g.FillRectangle(GrayBrush, this.imagePosX+11,
this.imagePosY, 3, 24); // brace
g.FillRectangle(GrayBrush, this.imagePosX+11,
this.imagePosY+11, 5, 3);} // lock
// combination shape - reusable as a single item
public void Flower(Graphics g, Brush bFlowerColor, Pen pFlowerColor) {
// pedals
g.DrawArc(pFlowerColor, this.imagePosX, // down
this.imagePosY-8, 5, 15, 0, 180);
g.DrawArc(pFlowerColor, this.imagePosX-10, // left
this.imagePosY-8, 15, 5, 90, 180);
g.DrawArc(pFlowerColor, this.imagePosX, // up
this.imagePosY-17, 5, 15, 180, 180);
g.DrawArc(pFlowerColor, this.imagePosX+1, // right
this.imagePosY-8, 15, 5, 270, 180);
// center
g.FillEllipse(bFlowerColor, this.imagePosX-2,
this.imagePosY-10, 10, 10);
// base
Point[] Vase = this.sharpTriangle();
g.FillPolygon(bFlowerColor, Vase);
}
// combination shape - reusable as a single item
public void TV(Graphics g, Brush bTVColor, Pen pTVColor) {
Brush GrayBrush = new SolidBrush(Color.Gray);
g.FillRectangle(GrayBrush, this.imagePosX, // console
this.imagePosY, 25, 15);
g.FillEllipse(bTVColor, this.imagePosX+1, // tube
this.imagePosY+1, 15, 13);
g.FillEllipse(bTVColor, this.imagePosX+18, // 1st dial
this.imagePosY+2, 5, 5);
g.FillEllipse(bTVColor, this.imagePosX+18, // 2nd dial
this.imagePosY+7, 5, 5);
g.DrawLine(pTVColor, this.imagePosX+12, this.imagePosY, // ant. left
this.imagePosX+5, this.imagePosY-5);
g.DrawLine(pTVColor, this.imagePosX+14, this.imagePosY, // ant. right
this.imagePosX+19, this.imagePosY-5);
}
// combination shape - reusable as a single item
public void Lamp(Graphics g, Brush LampColor, Brush LampshadeColor) {
Point[] DrawLamp = this.sharpTriangle();
Point[] DrawLampshade = this.Trapezoid();
g.FillPolygon(LampColor, DrawLamp);
g.FillPolygon(LampshadeColor, DrawLampshade);
}
// basic shape - reusable in many formats
public Point[] Trapezoid() {
Point[] Trapezoid = {new Point(this.imagePosX-5, this.imagePosY-10),
new Point(this.imagePosX+5, this.imagePosY-10),
new Point(this.imagePosX+10, this.imagePosY),
new Point(this.imagePosX-10, this.imagePosY)};
return(Trapezoid);
}
// basic shape - reusable in many formats
public Point[] sharpTriangle() {
Point[] sharpTriangle = {new Point(this.imagePosX, this.imagePosY-5),
new Point(this.imagePosX+3, this.imagePosY+10),
new Point(this.imagePosX-3, this.imagePosY+10)};
return(sharpTriangle);
}
}
}